package fhp.hlhj.giantfold.activity.message

import android.content.Intent
import android.net.Uri
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.adapter.ActiveMessageListAdp
import fhp.hlhj.giantfold.interfaces.IMsgList
import fhp.hlhj.giantfold.javaBean.MessageListBean
import fhp.hlhj.giantfold.presenter.MessageListPresenter
import kotlinx.android.synthetic.main.activity_active_message_aty.*

class ActiveMessageAty : BaseActivity(), IMsgList {


    override fun getContentId(): Int = R.layout.activity_active_message_aty
    private lateinit var presenter:MessageListPresenter
    private lateinit var listAdp:ActiveMessageListAdp
    private var page=0
    private  val datas=ArrayList<MessageListBean.DataBean>()

    override fun initView() {
        presenter= MessageListPresenter(this)

        val params = HttpParams()
        params.put("user_id",Contents.userId)
        params.put("page",page)
        params.put("type",intent.getStringExtra("type"))
        presenter.getList(params)
    }

    override fun initData() {
        listAdp= ActiveMessageListAdp(R.layout.active_message_item,datas)
        recyclerview.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        recyclerview.adapter=listAdp

        listAdp.setOnItemClickListener { adapter, view, position ->
            val intent = Intent(this@ActiveMessageAty,MessageDetailAty::class.java)

            intent.putExtra("url",datas[position].link)
            this.startActivity(intent)
        }
    }
    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }

    }


    override fun showLoading() {
        loadingDialog.show()
    }

    override fun onResp(messageListBean: MessageListBean) {
        loadingDialog.dismiss()
        if (messageListBean.code==200){
            datas.addAll(messageListBean.data)
            listAdp.notifyDataSetChanged()
        }
    }
}
